package com.shujia.wyh.day17;

/*
        预定义类
        \d == [0-9] 代表的是数字
        \D == [^0-9]代表的是非数字
        \s == 空白字符
        \w == [a-zA-Z0-9]
        \W == [^a-zA-Z0-9]
        .  == 任意字符
 */
public class RegularDemo5 {
    public static void main(String[] args) {
        String regex = "\\d";  // \\d代表转义，使用它原本的意思
        String str = "abcABC 1234  ERQcc2 1c21sDA Sadcs ABC Ca&.;12  3!";
        System.out.println("要匹配的字符串为：\n" + str);
        System.out.println("==========================================");
        System.out.println(str.replaceAll(regex, "_"));

        regex = "\\D";
        System.out.println(str.replaceAll(regex, "_"));

        regex = "\\s";
        System.out.println(str.replaceAll(regex, "_"));

        regex = "\\w";
        System.out.println(str.replaceAll(regex, "_"));

        regex = "\\W";
        System.out.println(str.replaceAll(regex, "_"));

        regex = ".";
        System.out.println(str.replaceAll(regex, "_"));

        //仅仅单纯要匹配一个字符.
        regex = "[.]";
        System.out.println(str.replaceAll(regex, "_"));
        regex = "\\.";
        System.out.println(str.replaceAll(regex, "_"));
    }
}
